import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Create a document.
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
# get active design and components
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Get the sheet metal rules
sheetMetalRules = design.librarySheetMetalRules
# Get the steel (default) rule then create a copy of it
steelRule = sheetMetalRules.item(0)
steelCopy = sheetMetalRules.addByCopy(steelRule, 'Steel Two (mm)')
# Make some changes to the copied rule
# First we can make some direct changes
steelCopy.kFactor = 0.5
steelCopy.twoBendReliefShape = adsk.fusion.TwoBendReliefShapes.RoundTwoBendReliefShape
steelCopy.twoBendReliefPlacement = adsk.fusion.TwoBendReliefPlacements.TangentTwoBendReliefPlacement
# Some changes need to be changed by value and can't be made directly on the rule
thicknessValue = steelCopy.thickness
thicknessValue.value = 0.02
gapValue = steelCopy.gap
gapValue.value = 0.03
# You can also delete rules, create a test and delete it
ruleToDelete = sheetMetalRules.addByCopy(steelCopy, 'Steel Three (mm)')
ruleToDelete.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#include <Core/Application/Application.h>
#include <Core/Application/Document.h>
#include <Core/Application/ValueInput.h>
#include <Core/UserInterface/UserInterface.h>
#include <Fusion/SheetMetal/SheetMetalRule.h>
#include <Fusion/SheetMetal/SheetMetalRules.h>
#include <Fusion/SheetMetal/SheetMetalValue.h>
using namespace adsk::core;
using namespace adsk::fusion;
Ptr<UserInterface> ui;
extern "C" XI_EXPORT bool run(const char* context)
{
Ptr<Application> app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
// Get active design
Ptr<Product> product = app->activeProduct();
if (!product)
return false;
Ptr<Design> design = product;
if (!design)
return false;
Ptr<SheetMetalRules> sheetMetalRules = design->librarySheetMetalRules();
if (!sheetMetalRules->item(0))
return false;
// Get the first sheet metal rule, it should be named "Steel (mm)" and should be in the library by default.
Ptr<SheetMetalRule> steelRule = sheetMetalRules->item(0);
if (!steelRule)
return false;
// Create a rule by copying the "Steel (mm)" rule.
Ptr<SheetMetalRule> steelRuleCopy = sheetMetalRules->addByCopy(steelRule, "Steel Two (mm)");
if (!steelRuleCopy)
return false;
// Some properties can be changed directly.
// Others need to be changed by value.
Ptr<SheetMetalRuleValue> thicknessValue = steelRuleCopy->thickness();
Ptr<SheetMetalRuleValue> gapValue = steelRuleCopy->gap();
// Example of creating a third rule, then deleting it.
Ptr<SheetMetalRule> ruleToDelete = sheetMetalRules->addByCopy(steelRuleCopy, "Steel Three (mm)");
return true;
}